#include "common/person.h"
#include <algorithm>
#include <boost/hana/functional/curry.hpp>
#include <functional>
#include <iostream>
#include <ostream>
#include <vector>

#include <boost/hana.hpp>

void print_person(const person_t& p, std::ostream& out, person_t::output_format_t format)
{
    p.print(out, format);
}

auto print_person_cd(const person_t& person)
{
    return [&](std::ostream& out) {
        return [&](person_t::output_format_t format) {
            print_person(person, out, format);
        };
    };
}

int main()
{
    std::vector<person_t> people {
        { "David", person_t::male },
        { "Jane", person_t::female },
        { "Martha", person_t::female },
        { "Peter", person_t::male },
        { "Rose", person_t::female },
        { "Tom", person_t::male }
    };

    // _1指向对象
    std::for_each(people.cbegin(), people.cend(),
        std::bind(&person_t::print, std::placeholders::_1, std::ref(std::cout), person_t::name_only));
    std::sort(people.begin(), people.end(), [](const person_t& p1, const person_t& p2) { return p1.name() < p2.name(); });
    std::for_each(people.cbegin(), people.cend(),
        [](const person_t& p) { p.print(std::cout, person_t::name_only); });
    print_person_cd(people.front())(std::cout)(person_t::name_only);
    auto print_person_cd_make = boost::hana::curry<3>(print_person);

    print_person_cd_make(people.back())(std::ref(std::cout))(person_t::name_only);
}